package com.example.productservice.config;

import com.example.productservice.model.Product;
import com.example.productservice.repository.ProductRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.math.BigDecimal;
import java.util.List;

@Configuration
public class DataInitializer {

    @Bean
    public CommandLineRunner initData(ProductRepository repository) {
        return args -> {
            Product product1 = new Product();
            product1.setName("iPhone 15 Pro");
            product1.setDescription("6.1英寸Super Retina XDR显示屏，A17 Pro芯片");
            product1.setPrice(new BigDecimal("8999.00"));
            product1.setStock(15);

            Product product2 = new Product();
            product2.setName("AirPods Pro (第二代)");
            product2.setDescription("主动降噪无线蓝牙耳机，空间音频");
            product2.setPrice(new BigDecimal("1899.00"));
            product2.setStock(8);

            Product product3 = new Product();
            product3.setName("MacBook Pro 14英寸");
            product3.setDescription("M2 Pro芯片，16GB内存，512GB SSD");
            product3.setPrice(new BigDecimal("14999.00"));
            product3.setStock(3);

            Product product4 = new Product();
            product4.setName("iPad Pro 12.9英寸");
            product4.setDescription("M2芯片，Liquid视网膜XDR显示屏");
            product4.setPrice(new BigDecimal("9299.00"));
            product4.setStock(12);

            Product product5 = new Product();
            product5.setName("Apple Watch Ultra");
            product5.setDescription("49mm钛金属表壳，精准定位功能");
            product5.setPrice(new BigDecimal("6299.00"));
            product5.setStock(7);

            repository.saveAll(List.of(product1, product2, product3, product4, product5));

            System.out.println("=== 商品数据初始化完成 ===");
            System.out.println("已创建 5 条商品记录");
            System.out.println("商品价格范围: ¥1899.00 - ¥14999.00");
        };
    }
}